import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.util.List;

/**
 * 测试API响应解析
 */
public class TestApiResponse {
    public static void main(String[] args) {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            
            // 读取demo/data.json文件
            File jsonFile = new File("demo/data.json");
            
            // 解析为CollegeApiResponse
            CollegeApiResponse response = objectMapper.readValue(jsonFile, CollegeApiResponse.class);
            
            System.out.println("解析成功！");
            System.out.println("状态码: " + response.getDataStatus().getStatusCode());
            System.out.println("状态描述: " + response.getDataStatus().getStatusDescription());
            System.out.println("总数据量: " + response.getDataStatus().getDataTotalCount());
            System.out.println("数据条数: " + response.getData().size());
            
            if (!response.getData().isEmpty()) {
                CollegeInfo firstCollege = response.getData().get(0);
                System.out.println("\n第一个高校信息:");
                System.out.println("学校名称: " + firstCollege.getCollegeName());
                System.out.println("学校UUID: " + firstCollege.getSchoolUUID());
                System.out.println("原始标签: " + firstCollege.getCollegeTags());
                System.out.println("解析后标签: " + firstCollege.getCollegeTagsList());
                System.out.println("分校区数量: " + firstCollege.getBranchList().size());
                System.out.println("分校区字符串: " + firstCollege.getBranchListAsStrings());
                System.out.println("隶属于: " + firstCollege.getAffiliatedTo());
                System.out.println("硕士点数量: " + firstCollege.getNumMaster());
                System.out.println("博士点数量: " + firstCollege.getNumDoctor());
            }
            
        } catch (Exception e) {
            System.err.println("解析失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}

// 简化的类定义（实际应该引用项目中的类）
class CollegeApiResponse {
    private DataStatus dataStatus;
    private List<CollegeInfo> data;
    
    // getters and setters
    public DataStatus getDataStatus() { return dataStatus; }
    public void setDataStatus(DataStatus dataStatus) { this.dataStatus = dataStatus; }
    public List<CollegeInfo> getData() { return data; }
    public void setData(List<CollegeInfo> data) { this.data = data; }
    
    static class DataStatus {
        private Integer statusCode;
        private String statusDescription;
        private Integer dataTotalCount;
        
        // getters and setters
        public Integer getStatusCode() { return statusCode; }
        public void setStatusCode(Integer statusCode) { this.statusCode = statusCode; }
        public String getStatusDescription() { return statusDescription; }
        public void setStatusDescription(String statusDescription) { this.statusDescription = statusDescription; }
        public Integer getDataTotalCount() { return dataTotalCount; }
        public void setDataTotalCount(Integer dataTotalCount) { this.dataTotalCount = dataTotalCount; }
    }
}

class CollegeInfo {
    private String collegeName;
    private String schoolUUID;
    private String collegeTags;
    private List<Branch> branchList;
    private String affiliatedTo;
    private Integer numMaster;
    private Integer numDoctor;
    
    // getters and setters
    public String getCollegeName() { return collegeName; }
    public void setCollegeName(String collegeName) { this.collegeName = collegeName; }
    public String getSchoolUUID() { return schoolUUID; }
    public void setSchoolUUID(String schoolUUID) { this.schoolUUID = schoolUUID; }
    public String getCollegeTags() { return collegeTags; }
    public void setCollegeTags(String collegeTags) { this.collegeTags = collegeTags; }
    public List<Branch> getBranchList() { return branchList; }
    public void setBranchList(List<Branch> branchList) { this.branchList = branchList; }
    public String getAffiliatedTo() { return affiliatedTo; }
    public void setAffiliatedTo(String affiliatedTo) { this.affiliatedTo = affiliatedTo; }
    public Integer getNumMaster() { return numMaster; }
    public void setNumMaster(Integer numMaster) { this.numMaster = numMaster; }
    public Integer getNumDoctor() { return numDoctor; }
    public void setNumDoctor(Integer numDoctor) { this.numDoctor = numDoctor; }
    
    public List<String> getCollegeTagsList() {
        // 简化的解析逻辑
        if (collegeTags != null && collegeTags.startsWith("[") && collegeTags.endsWith("]")) {
            String content = collegeTags.substring(1, collegeTags.length() - 1);
            return java.util.Arrays.asList(content.split(",\\s*"));
        }
        return java.util.Collections.emptyList();
    }
    
    public List<String> getBranchListAsStrings() {
        if (branchList == null) return java.util.Collections.emptyList();
        return branchList.stream()
            .map(b -> b.getBranchName() + " - " + b.getBranchAddress())
            .collect(java.util.stream.Collectors.toList());
    }
    
    static class Branch {
        private String branchName;
        private String branchAddress;
        
        public String getBranchName() { return branchName; }
        public void setBranchName(String branchName) { this.branchName = branchName; }
        public String getBranchAddress() { return branchAddress; }
        public void setBranchAddress(String branchAddress) { this.branchAddress = branchAddress; }
    }
}